package cn.lqs.basic.service.impl;



import cn.lqs.basic.mapper.BaseMapper;
import cn.lqs.basic.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    /**
     *      查询所有
     * @return
     */
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    /**
     *      通过id查询单个
     * @param id
     * @return
     */
    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    /**
     *  增加  保存
     * @param t
     */
    @Transactional
    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    /**
     *      通过id删除
     * @param id
     */
    @Transactional
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    /**
     *      修改
     * @param t
     */
    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }
}
